<?php

/**
 * Description of Site
 *
 * @author DENY PRASETIA TW
 * http://denyprasetiatw.blogspot.com/
 * Created Feb 10, 2012 - 12:15:59 AM
 */
class Site extends CI_Controller {
    
    private $template;

    public function __construct() {
        parent::__construct();
        $this->load->model(array('Pegawai', 'Klasifikasi'));
    }
    
    public function index() {
        $this->menu('');
    }
    
    public function menu($input) {
        
        //SET TOP MENU
        if($this->session->userdata('s_hakakses') == NULL){
            $this->template['topmenu']    = array(
                'Login'             => "Log In"
            );
        } else if($this->session->userdata('s_hakakses') == "1"){
            $this->template['topmenu']    = array(
                'Registrasi'        => "Registrasi",
                'Datapegawai'       => "Datapegawai",
                'Databidang'        => "Pedomanklasifikasi",
                'Formmetadata'      => "Formmetadata"
            );
        } else if($this->session->userdata('s_hakakses') == "2"){
            $this->template['topmenu']    = array(
                'Dataarsip'         => "Dataarsip",
                'Databidang'        => "Pedomanklasifikasi"
            );
        } else if($this->session->userdata('s_hakakses') == "3"){
            $this->template['topmenu']    = array(
                'Dataarsip'         => "Dataarsip",
                'Databidang'        => "Pedomanklasifikasi"
            );
        }

        //SETING LOAD AWAL MENU
        if($this->session->userdata('s_hakakses') == "1"){
            $this->template['dynamiccontent'] = 'Tatausaha';
        } else if($this->session->userdata('s_hakakses') == "2"){
            $this->template['dynamiccontent'] = 'Kepalabalai';
        } else if($this->session->userdata('s_hakakses') == "3"){
            $this->template['dynamiccontent'] = 'Pegawai';
        } else{
            $this->template['dynamiccontent'] = 'Login';
        }           
            
        //PILIH MENU
        switch ($input) {
            case "Datapegawai":
                $this->template['daftarpegawai']  = $this->Pegawai->lihatDaftarPegawai();
                $this->template['dynamiccontent'] = $input;
                $this->load->view('Home', $this->template);
                break;
            case "Registrasi":
                $this->template['dynamiccontent'] = $input;
                $this->load->view('Home', $this->template);
                break;
            case "Caripegawai":
                $input = array( 'namaPegawai' => $this->input->post('i_namaPegawai'));
                $this->template['daftarpegawai']  = $this->Pegawai->cariDataPegawai($input); 
                $this->template['dynamiccontent'] = 'Datapegawai';
                $this->load->view('Home', $this->template);
                break;
            case "Editpegawai":
                $this->template['dynamiccontent'] = $input;
                $this->load->view('Home', $this->template);
                break;
            case "Databidang":
                $this->template['daftarbidang']   = $this->Klasifikasi->tampilkanBidang();
                $this->template['dynamiccontent'] = $input;
                $this->load->view('Home', $this->template);
                break;
            case "Datapokok":
                $this->template['dynamiccontent'] = $input;
                $this->load->view('Home', $this->template);
                break;
            case "Datasub":
                $this->template['dynamiccontent'] = $input;
                $this->load->view('Home', $this->template);
                break;
            case "Formmetadata":
                $this->template['dynamiccontent'] = $input;
                $this->load->view('Home', $this->template);
                break;
            default:
                $this->load->view('Home', $this->template);
                break;
        }
        
    }
    
/*==============================================================*/
/* CLASS : PEGAWAI
 * VALIDASI LOGIN PEGAWAI*/
/*==============================================================*/
    public function validasiLogIn() {
        $input = array(
            'idpegawai' => $this->input->post('i_idpegawai'),
            'password'  => $this->input->post('i_password')
        );

        $this->form_validation->set_rules('i_idpegawai', 'Nip',      'required');
        $this->form_validation->set_rules('i_password',  'Password', 'required');
        
        if($this->form_validation->run() == FALSE){
            $this->index();
        }else{
            $hasilLogin = $this->Pegawai->logIn($input);
            if($hasilLogin != NULL){
                foreach ($hasilLogin as $val) {
                    $this->session->set_userdata('s_idpegawai',   $val['IDPEGAWAI']);
                    $this->session->set_userdata('s_namapegawai', $val['NAMAPEGAWAI']);
                    $this->session->set_userdata('s_password',    $val['PASSWORD']);
                    $this->session->set_userdata('s_hakakses',    $val['HAKAKSES']);
                    $this->session->set_userdata('s_status',      $val['STATUSPEGAWAI']);
                }
                redirect();
            }else{
                redirect();
            }
        }
    }
    
/*==============================================================*/
/* CLASS : PEGAWAI
 * VALIDASI LOGOUT PEGAWAI*/
/*==============================================================*/
    public function validasiLogOut() {
        $this->Pegawai->logOut();
    }
    
/*==============================================================*/
/* CLASS : PEGAWAI
 * VALIDASI REGISTRASI PEGAWAI */
/*==============================================================*/
    public function validasiRegistrasiPegawai() {
        $input = array(
            'idpegawai'     => $this->input->post('i_idpegawai'),
            'namapegawai'   => $this->input->post('i_namapegawai'),
            'password'      => $this->input->post('i_password'),
            'hakakses'      => $this->input->post('i_hakakses')
        );
        
        $this->form_validation->set_rules('i_idpegawai',   'Nip',      'required|min_length[5]|max_length[18]');
        $this->form_validation->set_rules('i_namapegawai', 'Nama',     'required|min_length[6]|max_length[25]');
        $this->form_validation->set_rules('i_password',    'Password', 'required|min_length[8]|max_length[15]');
        $this->form_validation->set_rules('i_hakakses',    'Jabatan',  'required');
        
        if($this->form_validation->run() == FALSE){
            $this->menu('Registrasi');
        }else{
            $this->Pegawai->registrasiPegawai($input);
            $this->menu('Datapegawai');
        }
        
    }
    
/*==============================================================*/
/* CLASS : PEGAWAI
 * VALIDASI EDIT PEGAWAI */
/*==============================================================*/
    public function validasiEditDataPegawai($id) {
        $input['idpegawai'] = $id;
        if($input['idpegawai'] == NULL){
            $this->menu('Datapegawai');
        }else{
            $this->template['datapegawai'] = $this->Pegawai->lihatDetailPegawai($input);
            $this->menu("Editpegawai");
        }
    }
    
/*==============================================================*/
/* CLASS : PEGAWAI
 * VALIDASI EDIT PEGAWAI */
/*==============================================================*/
    public function validasiSimpanEditDataPegawai() {
        $input = array(
            'idpegawai'     => $this->input->post('i_idpegawai'),
            'namapegawai'   => $this->input->post('i_namapegawai'),
            'password'      => $this->input->post('i_password'),
            'hakakses'      => $this->input->post('i_hakakses'),
            'statuspegawai' => $this->input->post('i_statuspegawai'),
        );
        
        $this->form_validation->set_rules('i_idpegawai',   'Nip',      'required|min_length[5]|max_length[18]');
        $this->form_validation->set_rules('i_namapegawai', 'Nama',     'required|min_length[6]|max_length[25]');
        $this->form_validation->set_rules('i_password',    'Password', 'required|min_length[8]|max_length[15]');
        $this->form_validation->set_rules('i_hakakses',    'Jabatan',  'required');
        
        if($this->form_validation->run() == FALSE){
            $this->menu('Registrasi');
        }else{
            $this->Pegawai->editDataPegawai($input);
            $this->menu('Datapegawai');
        }
    }
    
    public function validasiTampilkanPokok($id) {
        $input['idBidang'] = $id;
        if($input['idBidang'] == NULL){
            $this->menu('Databidang');
        }else{
            $this->template['datapokok'] = $this->Klasifikasi->tampilkanPokok($input);
            $this->menu("Datapokok");
        }
    }

    public function validasiTampilkanSub($id) {
        $input['idPokok'] = $id;
        if($input['idPokok'] == NULL){
            $this->menu('Datasub');
        }else{
            $this->template['datasub'] = $this->Klasifikasi->tampilkanSub($input);
            $this->menu("Datasub");
        }
    }
    
   
   
}

?>
